<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Created by PhpStorm.
 * User: zhaojia
 * Date: 15-9-18
 * Time: 下午1:52
 */
class Ask extends CI_Controller{
    public function __construct(){
        parent::__construct();
        $this->load->model('Question');
//        $this->load->model('Bangzhu');
    }

    public function index(){

        $perPage=11;
        $this->load->library('pagination');
        $config['first_link'] = '首页';
        $config['last_link'] = '尾页';
        $config['prev_link'] = '上一页';
        $config['next_link'] = '下一页';
        $config['base_url'] = site_url('/admin/ask/index');
        $config['total_rows'] =$this->db->count_all_results('question');
        $config['per_page'] = $perPage;
        $config['uri_segment'] = 4;
        $this->pagination->initialize($config);
        $data['links']=$this->pagination->create_links();

        $offset=$this->uri->segment(4);
        $this->db->limit($perPage,$offset);
        $data['question']=$this->Question->get_data();

        $this->load->view('admin/help_ask.html',$data);
    }

    public function add_ask(){
        if($_POST){
            $data=$this->input->post();
            $this->Question->add_data($data);
            redirect('admin/Ask/index');
        }
        $data['cate']=$this->Bangzhu->get_data();
        $this->load->view('admin/help_question.html',$data);
    }

    public function  edit(){
        $id=$this->uri->segment(4);

        if($_POST){
            $data=$this->input->post();
            $this->Question->save_data($data,$id);
            redirect('admin/Ask/index');
        }
        //问题分类

        $data['question']=$this->Question->get_data($id);

        $this->load->view('admin/edit_news.html',$data);
    }

    public function del(){

        $id=$this->uri->segment(4);
        $this->Question->del_data($id);
        redirect('admin/Ask/index');
    }


}
